package proxy;


import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class proxyUtils {
    public static Star createProxy(Star bigstar){
        Star starproxy = (Star) Proxy.newProxyInstance(proxyUtils.class.getClassLoader(),
                new Class[]{Star.class}, new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        if (method.getName().equals("sing")) {
                            System.out.println("收钱20万");
                        } else if (method.getName().equals("dance")) {
                            System.out.println("收钱100万");
                        }
                        return method.invoke(bigstar, args);
                    }
                });
        return starproxy;
    }

}
